<?php
/**
 * @author wyl
 * @date 2015-12-16 09:13:58
 * @use:  ./yiic batchcustomer or ./yiic batchcustomer 1027 100 or ./yiic batchcustomer 1027
 */
Yii::import('dao.bidAuction.BidAuction');
Yii::import('dao.RegisterDao');
Yii::import('dao.bid.BidDao');
class BatchCustomerCommand extends CConsoleCommand{
	public $customerCount=100;
	public $username;
	public $_bidDao;
	public $bids=100;
	public $bidType='cash';
    
    public function rand_username( $length = 6 ) {
        $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
        $username = '';
        for ( $i = 0; $i < $length; $i++ )
        {
            $username .= $chars[ mt_rand(0, strlen($chars) - 1) ];
        }
        return $username;
    }
	
    public function init(){
        $this->_bidDao=new BidDao();
    }
    
    public function run($args){
       
	   if (!empty($args[0])){
	       $this->customerCount=$args[0];
	   }
	   
	   if (!empty($args[1])){
	       $this->bids=$args[1];
	   }
	   
	   for($i=0;$i<$this->customerCount;$i++){
           $this->username=$this->rand_username();
	       $dao=new Customer('presure');
	       $dao->attributes=array(
	           'user_name'=>$this->username,
	           'password'=>md5($this->username),
	           'email'=>$this->username.'@presure.com',
	           'created'=>time(),
	           'status'=>1,
	       );
	       $result=$dao->save(false);
	       if ($result){
	           $this->_bidDao->customerId=$dao->id;
	           $this->_bidDao->getBidModel($this->bidType)->setBid($this->bids,'PRESURE');
	       }  
	   } 
  	}
}